package com.rainng.coursesystem.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rainng.coursesystem.dao.mapper.CheckFileByPrjMapper;
import com.rainng.coursesystem.dao.mapper.CheckFileMapper;
import com.rainng.coursesystem.dao.mapper.TreatResultMapper;
import com.rainng.coursesystem.model.shitong.*;
import com.rainng.coursesystem.model.vo.response.ResultVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

import static com.rainng.coursesystem.model.constant.GeneralReportProjectMap.ONLINE_PRJ_LIST;

@Service
public class TreatResultService extends BaseService {

    @Resource
    private TreatResultMapper mapper;

    //视同
    public ResultVO readFileCache(TreatResultVo vo) {
        int i = mapper.countTreatResult(vo.getPrjNum(), vo.getApplyNum());
        if (i == 0) {
            return result("");
        }
        String res = mapper.getTreatResult(vo.getPrjNum(), vo.getApplyNum());
        return result(res);
    }

    public ResultVO deleteFile(TreatResultVo vo) {
        int i = mapper.deleteTreatResult(vo.getPrjNum(), vo.getApplyNum());
        return result("删除成功");
    }

    public ResultVO writeFileCache(TreatResultVo vo) {


        int i = mapper.countTreatResult(vo.getPrjNum(), vo.getApplyNum());

        if (i == 0) {
            //Map<String, String> m = vo.getInfo();
            String json = vo.getInfo();
            int j = mapper.saveTreatResult(vo.getPrjNum(), vo.getApplyNum(), json);
            return result("暂存成功");
        }

        String json = vo.getInfo();
        int j = mapper.updateTreatResult(vo.getPrjNum(), vo.getApplyNum(), json);
        return result("暂存成功");
    }


    //实测
    public ResultVO readTrial(TreatResultVo vo) {
        int i = mapper.countTrialResult(vo.getPrjNum(), vo.getApplyNum());
        if (i == 0) {
            return result("");
        }
        String res = mapper.getTrialResult(vo.getPrjNum(), vo.getApplyNum());
        return result(res);
    }

    public ResultVO deleteTrial(TreatResultVo vo) {
        int i = mapper.deleteTrialResult(vo.getPrjNum(), vo.getApplyNum());
        return result("删除成功");
    }

    public ResultVO writeTrial(TreatResultVo vo) {


        int i = mapper.countTrialResult(vo.getPrjNum(), vo.getApplyNum());

        if (i == 0) {
            //Map<String, String> m = vo.getInfo();
            String json = vo.getInfo();
            int j = mapper.saveTrialResult(vo.getPrjNum(), vo.getApplyNum(), json);
            return result("暂存成功");
        }

        String json = vo.getInfo();
        int j = mapper.updateTrialResult(vo.getPrjNum(), vo.getApplyNum(), json);
        return result("暂存成功");
    }

}
